//
// Created by zhouyi on 2020/6/11.
//
#include <stdlib.h>

#include "include/tools.h"

int *twoSum(const int *nums, int numsSize, int target, int *returnSize);


int main(int argc, char *argv[]) {
    int returnSize[2] = { 1, 2 };
    int num[4] = { 2, 7, 11, 15 };
    int *result = twoSum(num, 4, 9, returnSize);

    printIntArray(num, 4);
    printIntArray(result, 2);

    return 0;
}

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int *twoSum(const int *nums, int numsSize, int target, int *returnSize) {

    int *result = malloc(sizeof(int) * 2);

    for (int i = 0; i < numsSize - 1; ++i) {
        for (int j = i + 1; j < numsSize; ++j) {
            if (nums[i] + nums[j] == target) {
                result[0] = i;
                result[1] = j;
                *returnSize = 2;
                return result;
            }
        }
    }

    return result;
}






